<?php
namespace ZHMVC\DB\MANAGER;
if (! isset($_SESSION)) {
    session_start();
}
include (dirname(dirname(__FILE__)) . "/zhconfig/Config.php");
include (ZH_PATH . DS . MANAGERFPATH . DS . 'islogin' . ZH);
$isp = new \ZHMVC\D\MANAGER\isPermission();
$isper = $isp->getPermission();
$_curlid = $isp->getCUrl();
$c = new \ZHCONFIG\ZhConfig();
$db_pre = $c->getDbPre();
if($isper==1)
{
    $ErrMsg="对不起，你没有访问该页面的权限";
    echo $ErrMsg;
    exit;
}
elseif($isper==0)
{
    $ErrMsg="对不起，地址错误";
    echo $ErrMsg;
    exit;
}

$admin_global_class = array(
    "网站前台设置",
    "SEO优化设置",
    "系统参数配置",
    //"会员登录和注册",
    //"图片上传设置",
    "公司信息设置"
);

$admin_global = array(
    
    "SiteName" => array(
        "des" => '网站名称',
        "type" => '字符型',
        "class" => '网站前台设置'
    ),
    
    "SiteUrl" => array(
        "des" => '使用域名,范例：http://www.yourdomain.com<br /><i style=color:red>若为二级目录安装，则需填写二级目录,范例:http://www.yourdamain.com/upload</i>',
        "type" => '字符型',
        "class" => '网站前台设置'
    ),
    
    "SiteQQ" => array(
        "des" => '客服QQ，请只填写一个',
        "type" => '字符型',
        "class" => '网站前台设置'
    ),
    
    "SiteEmail" => array(
        "des" => '客服邮箱',
        "type" => '字符型',
        "class" => '网站前台设置'
    ),
    
    "SiteTel" => array(
        "des" => '客服热线',
        "type" => '字符型',
        "class" => '网站前台设置'
    ),
    
    "SiteBeian" => array(
        "des" => '网站备案号',
        "type" => '字符型',
        "class" => '网站前台设置'
    ),
    
    "SiteLogo" => array(
        "des" => '网站Logo路径',
        "type" => '字符型',
        "class" => '网站前台设置'
    ),
    
    "SiteStat" => array(
        "des" => '第三方网站统计代码<br />如有单引号，建议你手动将其改为<b>双引号</b>，否则保存后可能造成系统显示空白，以至无法运行',
        "type" => '字符型',
        "class" => '网站前台设置'
    ),
    
    "SiteSeoName" => array(
        "des" => '网站标题，用于搜索引擎优化，请适当出现关键词',
        "type" => '字符型',
        "class" => 'SEO优化设置'
    ),
    
    "SiteKeywords" => array(
        "des" => '网站关键词，多个关键词以“,”分隔开',
        "type" => '字符型',
        "class" => 'SEO优化设置'
    ),
    
    "SiteDescription" => array(
        "des" => '网站描述，不超过255个字符',
        "type" => '字符型',
        "class" => 'SEO优化设置'
    ),
    
    "cfg_tpl_dir" => array(
        "des" => '模板目录，<i style=color:red>注意：相对/s/t/目录，默认为default</i>',
        "type" => '字符型',
        "class" => '系统参数配置'
    ),
    
    "cfg_if_site_open" => array(
        "des" => '开启关闭网站，<i style=color:red>请注意：非特殊情况，请勿关闭网站，对搜索引擎排名影响甚大！</i>',
        "type" => '布尔型',
        "class" => '系统参数配置'
    ),
    
    "cfg_site_open_reason" => array(
        "des" => '若关闭网站，前台页面显示提示（关闭原因）',
        "type" => '字符型',
        "class" => '系统参数配置'
    ),
    
    "cfg_page_line" => array(
        "des" => '分页每页显示记录数',
        "type" => '字符型',
        "class" => '系统参数配置'
    ),
    /*
     "cfg_if_member_register" => array(
     "des" => '是否开启新会员注册',
     "type" => '布尔型',
     "class" => '会员登录和注册'
     ),

     "cfg_if_member_log_in" => array(
     "des" => '是否开启会员登录',
     "type" => '布尔型',
     "class" => '会员登录和注册'
     ),

     "cfg_upimg_watermark" => array(
     "des" => '上传图片是否开启水印，<i style=color:red>注意：该功能需要您的服务器支持GD库</i>',
     "type" => '布尔型',
     "class" => '图片上传设置'
     ),

     "cfg_upimg_watermark_value" => array(
     "des" => '水印显示的内容<br /><i style=color:red>注意：仅支持英文，不支持中文，一般填写网站的域名</i>',
     "type" => '字符型',
     "class" => '图片上传设置'
     ),

     "cfg_upimg_watermark_position" => array(
     "des" => '上传图片水印显示的位置。<br /><i style=color:red>注意：1为左下角,2为右下角,3为左上角,4为右上角,5为居中</i>',
     "type" => '字符型',
     "class" => '图片上传设置'
     ),

     "cfg_upimg_watermark_color" => array(
     "des" => '水印文字的颜色，可选：白色，红色，黑色<br /><i style=color:red>白色为1，红色为2，黑色为3</i>',
     "type" => '字符型',
     "class" => '图片上传设置'
     ),
     */
    "company_name" => array(
        "des" => '公司名称',
        "type" => '字符型',
        "class" => '公司信息设置'
    ),
    
    "company_address" => array(
        "des" => '公司地址',
        "type" => '字符型',
        "class" => '公司信息设置'
    ),
    
    "company_postcode" => array(
        "des" => '邮政编码',
        "type" => '字符型',
        "class" => '公司信息设置'
    ),
    
    "company_linkman" => array(
        "des" => '联系人',
        "type" => '字符型',
        "class" => '公司信息设置'
    ),
    
    "company_mobil" => array(
        "des" => '手机号码',
        "type" => '字符型',
        "class" => '公司信息设置'
    ),
    
    "company_tel" => array(
        "des" => '电话号码',
        "type" => '字符型',
        "class" => '公司信息设置'
    ),
    
    "company_email" => array(
        "des" => '电子邮箱',
        "type" => '字符型',
        "class" => '公司信息设置'
    ),
    
    "company_yynum" => array(
        "des" => '时段预约次数',
        "type" => '字符型',
        "class" => '公司信息设置'
    ),
    
    "company_qq" => array(
        "des" => 'QQ号码',
        "type" => '字符型',
        "class" => '公司信息设置'
    ),
    
    "company_weixinimg" => array(
        "des" => '微信图标',
        "type" => '字符型',
        "class" => '公司信息设置'
    ),
    
    "company_businesslicense" => array(
        "des" => '营业执照',
        "type" => '字符型',
        "class" => '公司信息设置'
    )
    
);

include (ZH_PATH . DS . MANAGERFPATH . DS . 'top1' . ZH);
?>
<div class="wap-container">
	<nav class="breadcrumb" style="background-color:#fff;padding: 0 24px">
	系统设置
	<a class="btn btn-success radius f-r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
	</nav>
<!--/_header 作为公共模版分离出去-->
<?php 
$action=SafeRequest(getPGC('action'),0);

switch ($action)
{
    case "save":
        save($admin_global_class,$admin_global,$db_pre);
        break;
    default:
        main($admin_global_class,$admin_global,$db_pre);
}

function main($admin_global_class,$admin_global,$db_pre)
{
    $rs=D("zhmvc_config")->getLinkAll("",true);
    $datas = $rs['datas'];
    $rows = $rs['rows'];
    for ($j = 0; $j < $rows; $j ++) {
        $data[$datas[$j]['name']] = $datas[$j]['value'];
    }
    
?>
	<article class="Hui-admin-content clearfix">
	<div class="panel">
	<div class="panel-body">
	<form action="?action=save" method="post" class="form form-horizontal" name="form1" id="form1">
	<div id="tab-system" class="HuiTab">
	<div class="tabBar cl">
    	<span>网站前台</span>
    	<span>SEO优化</span>
    	<span>系统参数</span>
    	<!-- <span>会员登录和注册</span>
    	<span>图片上传</span> -->
    	<span>公司信息</span>
	</div>
    <?php 
    foreach($admin_global_class as $k =>$zhmvc_v){
    ?>
    <div class="tabCon">
      <?php 
      foreach ($admin_global as $k =>$a){
          if ($a["class"]==$zhmvc_v){
              if(!isset($data[$k]))
              {
                  $valuezhi="";
              }
              else 
              {
                  $valuezhi=$data[$k];
              }
              
	  ?>
	  		<div class="row clearfix">
				<label class="form-label col-xs-6 col-sm-2"><?php echo $a["des"];?>：</label>
					<div class="form-controls col-xs-6 col-sm-9">
                <?php 
                if($k == 'SiteDescription' || $k == 'SiteStat' || $k == 'cfg_forbidden_post_ip' || $k =='cfg_site_open_reason'){
                    echo "<textarea name=\"".$k."\" class=\"textarea\" style=\"height:100px\">".$valuezhi."</textarea>";
                }
                elseif($k == 'SiteLogo')
                {
                    echo "<input name=\"".$k."\" type=\"text\" class=\"input-text upload-url\" value=\"".$valuezhi."\" readonly=\"true\"><br />&nbsp;<iframe name=\"up\" frameborder=\"0\" width=\"300\" height=\"60\" scrolling=\"no\" src=\"/common/tool/upload/uploadfile.php?formname=form1&frominputname=".$k."\"></iframe>";
                    if($valuezhi) 
                    { 
                        echo "<a href=\"".$valuezhi."\" target=\"_blank\"><img src=\"".$valuezhi."\" alt=\"\" height=\"30\" width=\"80\" />预览图片</a>";
                    } 
                }
                elseif($k == 'company_weixinimg')
                {
                    echo "<input name=\"".$k."\" type=\"text\" class=\"input-text upload-url\" value=\"".$valuezhi."\" readonly=\"true\"><br />&nbsp;<iframe name=\"up\" frameborder=\"0\" width=\"300\" height=\"60\" scrolling=\"no\" src=\"/common/tool/upload/uploadfile.php?formname=form1&frominputname=".$k."\"></iframe>";
                    if($valuezhi)
                    {
                        echo "<a href=\"".$valuezhi."\" target=\"_blank\"><img src=\"".$valuezhi."\" alt=\"\" height=\"30\" width=\"80\" />预览图片</a>";
                    }
                }
                else
                {
                    if($a["type"]=="布尔型"){
                        echo "<select class=\"select\" name=\"".$k."\"/>";
                        echo "<option value=\"1\"";
                        echo ($valuezhi == 1)?" selected='selected' style='background-color:#6eb00c; color:white!important;'":"";
                        echo ">开启</option>";
                        echo "<option value=\"0\"";
                        echo  ($valuezhi == 0)?" selected='selected' style='background-color:#6eb00c; color:white!important;'":"";
                        echo ">关闭</option>";
                        echo "<select>";
                    }else{
                        echo "<input name=\"".$k."\" value=\"".$valuezhi."\" class=\"input-text\"/>";
                    }
                }
                echo ($a["type"]=="布尔型")?"&nbsp;":"<p class=\"help-block\" style='color:blue'>{@#\$".$k."#@}</p>";
                ?>
             	</div>
			</div>
       <?php 
			}
      }
       ?>
      </div>
    <?php 
    }
    ?>
		<div class="row clearfix">
							<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
								<button class="btn btn-primary radius" type="submit"><i class="Hui-iconfont">&#xe632;</i> 保存</button>
								<button class="btn btn-default radius" type="reset">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
							</div>
						</div>
					</form>
				</div>
			</div>
		</article>
	</div>
<?php 
}

function save($admin_global_class,$admin_global,$db_pre)
{

    foreach ($admin_global as $k =>$a){
        
        $zhi=SafeRequest(getPGC($k),0);
        if($zhi!="")
        {
            $map['name']=$k;
            $rs=D("zhmvc_config")->where($map)->getLinkAll("",true);
            $map=null;
            $datas = $rs['datas'];
            $rows = $rs['rows'];
            if($rows>0)
            {
                $wheremap=array();
                $updatedata=array();
                $wheremap['name']=$k;
                $updatedata["value"]=$zhi;
                D("zhmvc_config")->where($wheremap)->LinkUpdate($updatedata);
                $wheremap=null;
                $updatedata=null;
            }
            else
            {
                $updatedata=array();
                $updatedata["name"]=$k;
                $updatedata["value"]=$zhi;
                D("zhmvc_config")->LinkInsert($updatedata);
                $updatedata=null;
            }
        }
    }
    
    //$sysEditor=SafeRequest(getPGC('editor'),0);
    echo "<br>更新成功!";
}

include (ZH_PATH . DS . MANAGERFPATH . DS . 'foot1' . ZH);
?>
<script type="text/javascript">
$(function(){
	$("#tab-system").Huitab();
});
</script>
</body>
</html>